<template>
  <a-modal :open="open" :width="640" title="调整签停" centered :closable="false" ok-text="确定" @ok="onOk" @cancel="onCancel">
    <div class="pl-4 pr-2 pt-1 mb-2 pb-1 bg-black-1">
      <div>
        <template v-if="formState.advOrderType === 0">
          <DoctorAdviceOrder
            :row-data="formState"
            :params-key="{
              mc: 'adv.mc',
              gg: 'adv.gg',
              sl: 'clinicalDose',
              dw: 'clinicalDoseUnit',
              yf: 'deliverRoute.fyff',
              pl: 'fqy.plid',
              drugPathName: 'drugPathName'
            }"
          />
        </template>
        <template v-else>
          <a-tooltip>
            <template #title>{{ formState.advName }}</template>
            {{ formState.advName }}
          </a-tooltip>
        </template>
      </div>
    </div>
    <a-divider class="!my-2.5" />
    <a-form :model="formState" class="form-style-flex" :label-col="{ style: { width: '100px' } }">
      <a-form-item label="原签停人" class="w-1/2">
        {{ formState.signStopEmpName }}
      </a-form-item>
      <a-form-item label="调整签停人" class="w-1/2">
        <SelectTable
          v-model:value="formState.qtrEmpName"
          type="护士"
          @select="
            (event) => {
              formState.qtrEmpName = event.empName
              formState.qtrEmpId = event.empId
            }
          "
        />
      </a-form-item>
      <a-form-item label="原签停时间" class="w-1/2">
        {{ formState.signStopTime }}
      </a-form-item>
      <a-form-item label="调整签停时间" class="w-1/2">
        <a-date-picker v-model:value="formState.qtsj" show-time format="YYYY-MM-DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss" />
        <template #prefix>
          <LockOutlined class="text-primary text-base" />
        </template>
      </a-form-item>
    </a-form>
  </a-modal>
</template>
<script setup>
import { ref, watch } from 'vue'
import { message } from 'ant-design-vue'
import { LockOutlined } from '@ant-design/icons-vue'
import { post } from '@/utils/request'

const emit = defineEmits(['update:open', 'success'])
const props = defineProps({
  open: Boolean,
  rowData: {
    type: Object,
    default: () => ({})
  }
})
const formState = ref({})

const onOk = async () => {
  const res = await post('/inp/clinicalOrder/signStopAdviceInfo', {
    id: formState.value.id,
    qtsj: formState.value.qtsj,
    qtrEmpId: formState.value.qtrEmpId
  })
  if (res.code !== 0) return message.error(res.msg)
  emit('success')
  onCancel()
}
const onCancel = () => {
  emit('update:open', false)
}
watch(
  () => props.open,
  (val) => {
    if (val) {
      formState.value = { ...props.rowData }
    } else {
      formState.value = {}
    }
  }
)
</script>
<style lang="less" scoped>
.bg-black-1 {
  background: rgba(0, 0, 0, 0.1);
}
</style>
